home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
source
/
snip9503
/
prntself.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-14
|
734b
|
36 lines
/*
** PRNTSELF.C - A program which prints its own source
**
** public domain demo by Bob Stout
*/
#include <stdio.h>
#include <string.h>
main(int argc, char *argv[])
{
FILE *in;
char fname[13], *ptr;
char line[1024]; /* Nice & roomy */
/*
** Get the source name by replacing the executable's COM or EXE with C
*/
strcpy(fname, argv[0]);
ptr = strrchr(fname, '.');
strcpy(++ptr, "C");
/*
** Print its own source
*/
if (NULL != (in = fopen(fname, "r")))
{
while (NULL != fgets(line, 1023, in))
fputs(line, stdprn);
return 0;
}
else return -1;
}